package com.eims.sls_app.ui;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Adapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;

import bls.juejin.cn.R;

import com.eims.sls_app.dataaccess.AppGateway;
import com.eims.sls_app.dataaccess.Schemes;
import com.eims.sls_app.dataaccess.utils.HttpUtils;
import com.eims.sls_app.fragment.FollowFragment;
import com.eims.sls_app.protocol.MD5;
import com.eims.sls_app.protocol.RspBodyBaseBean;
import com.eims.sls_app.ui.AccountInformationActivity.MyAsynTaskBind;
import com.eims.sls_app.ui.adapter.AppGatewayAdapter;
import com.eims.sls_app.utils.App;
import com.eims.sls_app.utils.App;
import com.eims.sls_app.utils.BaseHelper;
import com.eims.sls_app.utils.MyAsynTaskWithProgress;
import com.eims.sls_app.utils.RequestUtil;
import com.eims.sls_app.view.MyToast;
import com.eims.sls_app.view.RoundProgressBar;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * 合买 选号详情
 * 
 * @author Kinwee 修改时间 2014-12-5
 * 
 */
@SuppressLint("HandlerLeak")
public class FollowInfoActivity extends MyBaseActivity implements OnClickListener {
	private static final String TAG = "FollowInfoActivity";
	private Context context = FollowInfoActivity.this;
	private Schemes schemes;
	private TextView follow_lv_tv_username, tv_yong, tv_numberInfo, tv_title,
			tv_content, tv_userName2,
			follow_lv_tv_lotteryname,
			follow_lv_iv_eachmoney, // 彩种名称// //每份金额
			follow_lv_iv_remain, follow_lv_iv_tatolmoney, tv_playType,
			tv_playType2; // 剩余份数// 总金额
	private ImageView follow_lv_iv_user_record1, follow_lv_iv_user_record2,
			follow_lv_iv_user_record3, follow_lv_iv_user_record4;
	private Button btn_info, btn_submit; // 查看详情// 付款
	private EditText et_count; // 购买份数

	// private TextView tv_showMoney; // 底部显示金额栏
	private TextView follow_detail_tv_remain; // 剩余份数

	private ImageButton btn_back;// 返回

	private Intent intent;
	private Bundle bundle;
	private String errormsg1 = "";

	private int buyShare = 1, remainShare = -1, schedule = 1;

	private String opt, auth, info, time, imei, crc; // 格式化后的参数
	private MyAsynTask myAsynTask;
	private MyHandler myHandler;

	private RoundProgressBar RoundPr;

	// listview
	public ListView listView;
	// adapter
	public AppGatewayAdapter appGatewayAdapter;
	// dialog
	private ProgressDialog dialog;
	// List集合
	private List<AppGateway> list_appGateWay;
	// 总
	private TextView tv_zong;

	private LinearLayout ll_vip;
	private MyAsynTaskBind asynTaskBind;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// 设置无标题
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		// getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
		setContentView(R.layout.activity_followinfo);
		App.activityS.add(this);
		findView();
		init();
		setListener();
		asynTaskBind = new MyAsynTaskBind();
		asynTaskBind.execute();
		
	}

	/** 初始化UI */
	private void findView() {
		tv_zong = (TextView) this.findViewById(R.id.tv_zong);
		ll_vip = (LinearLayout) this.findViewById(R.id.ll_vip);
		listView = (ListView) this.findViewById(R.id.listview_follow);
		follow_lv_tv_lotteryname = (TextView) this
				.findViewById(R.id.follow_lv_tv_lotteryname);
		follow_lv_iv_eachmoney = (TextView) this
				.findViewById(R.id.follow_lv_iv_eachmoney);
		follow_lv_iv_remain = (TextView) this
				.findViewById(R.id.follow_lv_iv_remain);
		follow_lv_iv_tatolmoney = (TextView) this
				.findViewById(R.id.follow_lv_iv_tatolmoney);
		follow_lv_tv_username = (TextView) this
				.findViewById(R.id.follow_lv_tv_username);

		// tv_bao = (TextView) this.findViewById(R.id.f_tv_top);
		RoundPr = (RoundProgressBar) this.findViewById(R.id.RoundProgressBar);
		tv_userName2 = (TextView) this.findViewById(R.id.info_tv_userName2);
		tv_yong = (TextView) this.findViewById(R.id.info_tv_yongjin2);
		tv_numberInfo = (TextView) this.findViewById(R.id.info_tv_numberInfo2);
		tv_title = (TextView) this.findViewById(R.id.info_tv_title2);
		//tv_content = (TextView) this.findViewById(R.id.info_tv_content2);//方案描述
		tv_playType = (TextView) this.findViewById(R.id.follow_tv_playType);
		tv_playType2 = (TextView) this.findViewById(R.id.follow_tv_playType2);
		follow_detail_tv_remain = (TextView) this
				.findViewById(R.id.follow_detail_tv_remain);
		btn_back = (ImageButton) this.findViewById(R.id.btn_back);

		follow_lv_iv_user_record1 = (ImageView) this
				.findViewById(R.id.follow_lv_iv_user_record1);
		follow_lv_iv_user_record2 = (ImageView) this
				.findViewById(R.id.follow_lv_iv_user_record2);
		follow_lv_iv_user_record3 = (ImageView) this
				.findViewById(R.id.follow_lv_iv_user_record3);
		follow_lv_iv_user_record4 = (ImageView) this
				.findViewById(R.id.follow_lv_iv_user_record4);

		et_count = (EditText) this.findViewById(R.id.et_count);// s输入框
		// et_count.addTextChangedListener(fen_watcher);
		// tv_showMoney = (TextView)
		// this.findViewById(R.id.info_bottom_tv_money);

		btn_info = (Button) this.findViewById(R.id.btn_numberInfo);// 公开里面的查看张按钮
		btn_submit = (Button) this.findViewById(R.id.btn_submit);// 立即付款
		// btn_max = (Button) this.findViewById(R.id.btn_maxCount);

	}

	/** 初始化属性 */
	private void init() {
		myHandler = new MyHandler();
		intent = getIntent();
		bundle = intent.getBundleExtra("bundle");
		schemes = (Schemes) bundle.getSerializable("schem");
		follow_lv_tv_username.setText(schemes.getInitiateName());
		tv_userName2.setText(schemes.getInitiateName());
		tv_yong.setText((int) (schemes.getSchemeBonusScale() * 100) + "%");
		follow_lv_tv_lotteryname.setText(schemes.getLotteryName());
		int remain = schemes.getSurplusShare();
		follow_detail_tv_remain.setText(remain + "");
		follow_lv_iv_remain.setText(remain + "份");
		follow_lv_iv_eachmoney.setText(schemes.getShareMoney() + "元");
		follow_lv_iv_tatolmoney.setText(schemes.getMoney() + "元");

		tv_playType2.setText(schemes.getPlayTypeName());

		RoundPr.setjidu(schemes.getSchedule(), (int) (schemes.getAssureMoney()
				/ schemes.getMoney() * 100)); // 方案进度 保底进度 半径

		// 先让奖牌不可见
		follow_lv_iv_user_record1.setVisibility(View.GONE);
		follow_lv_iv_user_record2.setVisibility(View.GONE);
		follow_lv_iv_user_record3.setVisibility(View.GONE);
		follow_lv_iv_user_record4.setVisibility(View.GONE);
		if (schemes.getLevel() == 0)
			follow_lv_iv_user_record1.setVisibility(View.VISIBLE);
		else if (schemes.getLevel() != 1) {
			follow_lv_iv_user_record1.setVisibility(View.VISIBLE);

			int level = schemes.getLevel();
			// int level = 9999;
			if (9999 < level) {// 1000以上
				setxin(follow_lv_iv_user_record1, follow_lv_iv_user_record2,
						follow_lv_iv_user_record3, follow_lv_iv_user_record4,
						View.VISIBLE);
				follow_lv_iv_user_record1
						.setBackgroundResource(App.level_crown_list.get(8));
				follow_lv_iv_user_record2
						.setBackgroundResource(App.level_cup_list.get(8));
				follow_lv_iv_user_record3
						.setBackgroundResource(App.level_medal_list.get(8));
				follow_lv_iv_user_record4
						.setBackgroundResource(App.level_star_list.get(8));
			} else if (level <= 9999 && level > 999) {// 含皇冠,奖杯，奖牌，星星
				setxin(follow_lv_iv_user_record1, follow_lv_iv_user_record2,
						follow_lv_iv_user_record3, follow_lv_iv_user_record4,
						View.VISIBLE);
				int crown = level / 1000;// 皇冠个数
				follow_lv_iv_user_record1
						.setBackgroundResource(App.level_crown_list
								.get(crown - 1));
				int cup = (level - 1000 * crown) / 100;// 奖杯个数
				// 从第二个图标开始，有可能取0个，需要进行判断，往下同理
				if (cup != 0) {
					follow_lv_iv_user_record2
							.setBackgroundResource(App.level_cup_list
									.get(cup - 1));
				} else {
					follow_lv_iv_user_record2.setVisibility(View.GONE);
				}
				int medal = (level - 1000 * crown - cup * 100) / 10;// 奖杯个数
				if (medal != 0) {
					follow_lv_iv_user_record3
							.setBackgroundResource(App.level_medal_list
									.get(medal - 1));
				} else {
					follow_lv_iv_user_record3.setVisibility(View.GONE);
				}
				int star = level - 1000 * crown - cup * 100 - medal * 10;// 星星个数
				if (star != 0) {
					follow_lv_iv_user_record4
							.setBackgroundResource(App.level_star_list
									.get(star - 1));
				} else {
					follow_lv_iv_user_record4.setVisibility(View.GONE);
				}
			} else if (level <= 999 && level > 99) {// 含奖杯，奖牌，星星
				follow_lv_iv_user_record2.setVisibility(View.VISIBLE);
				follow_lv_iv_user_record3.setVisibility(View.VISIBLE);
				follow_lv_iv_user_record4.setVisibility(View.VISIBLE);
				int cup = level / 100;// 奖杯个数
				follow_lv_iv_user_record2
						.setBackgroundResource(App.level_cup_list
								.get(cup - 1));
				int medal = (level - cup * 100) / 10;// 奖杯个数
				if (medal != 0) {
					follow_lv_iv_user_record3
							.setBackgroundResource(App.level_medal_list
									.get(medal - 1));
				} else {
					follow_lv_iv_user_record3.setVisibility(View.GONE);
				}
				int star = level - cup * 100 - medal * 10;// 星星个数
				if (star != 0) {
					follow_lv_iv_user_record4
							.setBackgroundResource(App.level_star_list
									.get(star - 1));
				} else {
					follow_lv_iv_user_record4.setVisibility(View.GONE);
				}
			} else if (level <= 99 && level > 9) {// 含奖牌，星星
				follow_lv_iv_user_record3.setVisibility(View.VISIBLE);
				follow_lv_iv_user_record4.setVisibility(View.VISIBLE);
				int medal = level / 10;// 奖杯个数
				follow_lv_iv_user_record3
						.setBackgroundResource(App.level_medal_list
								.get(medal - 1));
				int star = level - medal * 10;// 星星个数
				if (star != 0) {
					follow_lv_iv_user_record4
							.setBackgroundResource(App.level_star_list
									.get(star - 1));
				} else {
					follow_lv_iv_user_record4.setVisibility(View.GONE);
				}
				// int cup = (level - 1000 * crown) / 100;// 奖杯个数
				// follow_lv_iv_user_record2
				// .setBackgroundResource(App.level_cup_list
				// .get(cup - 1));
				// int medal = (level - 1000 * crown - cup * 100) / 10;// 奖杯个数
				// follow_lv_iv_user_record3
				// .setBackgroundResource(App.level_medal_list
				// .get(medal - 1));
				// int star = level - 1000 * crown - cup * 100 - medal * 10;//
				// 星星个数
				// follow_lv_iv_user_record4
				// .setBackgroundResource(App.level_star_list
				// .get(star - 1));
				// } else if (level <= 999 && level > 99) {// 含奖杯，奖牌，星星
				//
				// follow_lv_iv_user_record2.setVisibility(View.VISIBLE);
				// follow_lv_iv_user_record3.setVisibility(View.VISIBLE);
				// follow_lv_iv_user_record4.setVisibility(View.VISIBLE);
				// int cup = level / 100;// 奖杯个数
				// follow_lv_iv_user_record2
				// .setBackgroundResource(App.level_cup_list
				// .get(cup - 1));
				// int medal = (level - cup * 100) / 10;// 奖杯个数
				// follow_lv_iv_user_record3
				// .setBackgroundResource(App.level_medal_list
				// .get(medal - 1));
				// int star = level - cup * 100 - medal * 10;// 星星个数
				// follow_lv_iv_user_record4
				// .setBackgroundResource(App.level_star_list
				// .get(star - 1));
				// } else if (level <= 99 && level > 9) {// 含奖牌，星星
				// follow_lv_iv_user_record3.setVisibility(View.VISIBLE);
				// follow_lv_iv_user_record4.setVisibility(View.VISIBLE);
				// int medal = level / 10;// 奖杯个数
				// follow_lv_iv_user_record3
				// .setBackgroundResource(App.level_medal_list
				// .get(medal - 1));
				// int star = level - medal * 10;// 星星个数
				// follow_lv_iv_user_record4
				// .setBackgroundResource(App.level_star_list
				// .get(star - 1));
			} else if (level >= 1) {
				follow_lv_iv_user_record4.setVisibility(View.VISIBLE);
				follow_lv_iv_user_record4
						.setBackgroundResource(App.level_star_list
								.get(level - 1));
			}

			// Log.i(TAG, schemes.getSecrecyLevel()+"");
			// switch (schemes.getSecrecyLevel()) {
			// case 0:
			// tv_numberInfo.setText("公开");
			// break;
			// case 1:
			// tv_numberInfo.setText("到截止");
			// if (App.user == null
			// || !App.user.getName().equals(
			// tv_userName2.getText().toString().trim()))
			// btn_info.setVisibility(View.GONE);
			// break;
			// case 2:
			// tv_numberInfo.setText("到开奖");
			// if (App.user == null
			// || !App.user.getName().equals(
			// tv_userName2.getText().toString().trim()))
			// btn_info.setVisibility(View.GONE);
			// break;
			// }
		}
		if (schemes.getIsHide() == 0) {
			btn_info.setVisibility(View.VISIBLE);
		} else if (schemes.getIsHide() == 1) {
			btn_info.setVisibility(View.GONE);
		}

		tv_numberInfo.setText(schemes.getSecretMsg());

		tv_title.setText(schemes.getTitle());
		//tv_content.setText(schemes.getDescription());

		opt = "12";
		time = RspBodyBaseBean.getTime();
		imei = RspBodyBaseBean.getIMEI(getApplicationContext());
	}

	public void setxin(View v, View v1, View v2, View v3, int visible) {
		v.setVisibility(visible);
		v1.setVisibility(visible);
		v2.setVisibility(visible);
		v3.setVisibility(visible);
	}

	/** 绑定监听 */
	private void setListener() {
		btn_info.setOnClickListener(this);
		// btn_max.setOnClickListener(this);
		btn_back.setOnClickListener(this);
		btn_submit.setOnClickListener(this);
		et_count.addTextChangedListener(watcher);
	}

	/** 当文本的值改变时 */
	private TextWatcher watcher = new TextWatcher() {
		@Override
		public void onTextChanged(CharSequence arg0, int arg1, int arg2,
				int arg3) {
		}

		@Override
		public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
				int arg3) {
		}

		@Override
		public void afterTextChanged(Editable edt) {
			if (edt.toString().trim().length() != 0) {
				if (Integer.parseInt(edt.toString().trim()) > schemes
						.getSurplusShare()) {
					et_count.setText(schemes.getSurplusShare() + "");
					Toast.makeText(FollowInfoActivity.this, "最多购买" + schemes.getSurplusShare() + "份", Toast.LENGTH_SHORT).show();
					
				}
				if (edt.toString().substring(0, 1).equals("0")) {
					et_count.setText(edt.toString().substring(1,
							edt.toString().length()));
				}
			}
			show();
		}
	};

	/** 按钮点击监听 */
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		/** 查看投注详情 **/
		case R.id.btn_numberInfo:
			betInfo();
			break;
		/** 付款 **/
		case R.id.btn_submit:
			dopay();
			break;
		case R.id.btn_back:// 返回
			FollowInfoActivity.this.finish();
			break;
		}
	}

	/** 显示 **/
	private void show() {
		if (et_count.getText().toString().trim().length() == 0)
			buyShare = 1;
		else
			buyShare = Integer.parseInt(et_count.getText().toString().trim());
		// tv_showMoney.setText(buyShare + "份×" + schemes.getShareMoney() + "元="
		// + (buyShare * schemes.getShareMoney()) + "元");
	}

	/** 付款 */
	private void dopay() {
		if (App.user != null) {
			// myAsynTask = new MyAsynTask(context,"正在支付...");
			// myAsynTask.execute();
			commit();
		} else {
			Toast.makeText(FollowInfoActivity.this, "请先登陆", Toast.LENGTH_SHORT).show();
			Intent intent = new Intent(FollowInfoActivity.this,
					LoginActivity.class);
			intent.putExtra("loginType", "bet");
			FollowInfoActivity.this.startActivity(intent);
		}
	}

	public void commit() {
		RequestUtil requestUtil = new RequestUtil(context, false, 0, false,
				"正在支付...") {
			@Override
			public void responseCallback(JSONObject object) {
				if (RequestUtil.DEBUG)
					Log.i(TAG, "加入合买结果---" + object);
				if (null != object) {
					try {
						if ("0".equals(object.optString("error"))) {
							if (RequestUtil.DEBUG)
								Log.i(TAG, "加入合买成功  ");
							App.user.setBalance(object.getLong("balance"));
							App.user.setFreeze(object.getDouble("freeze"));
							remainShare = object.getInt("remainShare");
							schedule = object.getInt("currentSchedule");
							Toast.makeText(FollowInfoActivity.this, "加入合买成功", Toast.LENGTH_SHORT).show();
							for (int i = 0; i < FollowFragment.listSchemes
									.size(); i++) {
								if (FollowFragment.listSchemes.get(i).getId()
										.equals(schemes.getId())) {
									FollowFragment.listSchemes.get(i)
											.setSurplusShare(remainShare);
									FollowFragment.listSchemes.get(i)
											.setSchedule(schedule);
									if (schedule == 100)
										FollowFragment.listSchemes.remove(i);
								}
							}
							FollowInfoActivity.this.finish();
						} else if ("-115".equals(object.optString("error"))) {
							String msg = object.optString("msg");
							Toast.makeText(FollowInfoActivity.this, msg,
									Toast.LENGTH_SHORT).show();
							// TODO
							// intent = new
							// Intent(FollowInfoActivity.this,AmountOfCharge.class);
							Intent intent_alipay = new Intent();
							Bundle bundle_alipay = new Bundle();
							intent_alipay.setClass(FollowInfoActivity.this,
									AmountOfCharge.class);
							bundle_alipay.putInt("Type", 1);
							intent_alipay.putExtras(intent_alipay);
							// intent = new Intent();
							// intent.setClass(FollowInfoActivity.this,
							// PayWebActivity.class);
							FollowInfoActivity.this.startActivity(intent);
						} else {
							String msg = object.optString("msg");
							Toast.makeText(FollowInfoActivity.this, msg, Toast.LENGTH_SHORT).show();
						}
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
						Toast.makeText(FollowInfoActivity.this,"很抱歉,系统异常..." , Toast.LENGTH_SHORT).show();
						if (RequestUtil.DEBUG)
							Log.e(TAG, e.getMessage());
					}
				} else {
					Toast.makeText(FollowInfoActivity.this,"很抱歉,系统异常..." , Toast.LENGTH_SHORT).show();
				}
			}

			@Override
			public void responseError(VolleyError error) {
				Toast.makeText(FollowInfoActivity.this,"很抱歉,系统异常..." , Toast.LENGTH_SHORT).show();
				if (RequestUtil.DEBUG)
					Log.e(TAG, error.getMessage());
			}
		};
		requestUtil.joinFollow(schemes.getId(), buyShare,
				schemes.getShareMoney());
	}

	/** 查看投注详情 */
	private void betInfo() {
		if ("73".equals(schemes.getLotteryID())
				|| "72".equals(schemes.getLotteryID())
				|| "45".equals(schemes.getLotteryID())) {
			intent = new Intent(FollowInfoActivity.this,
					FollowNumberActivity_jc.class);
		} else {
			intent = new Intent(FollowInfoActivity.this,
					FollowNumberActivity.class);
		}
		intent.putExtra("bundle", bundle);
		FollowInfoActivity.this.startActivity(intent);
	}

	/** 异步任务 */
	class MyAsynTask extends MyAsynTaskWithProgress {
		/**
		 * @param context
		 *            上下文
		 * @param title
		 *            进度框显示文字
		 */
		public MyAsynTask(Context context, String title) {
			super(context, title);
		}

		/** 在后台执行的程序 */
		@Override
		protected String doInBackground(Integer... params) {

			Log.i("x", "buyShare------" + buyShare);

			info = RspBodyBaseBean.changeFollow_info(schemes.getId(), buyShare,
					schemes.getShareMoney());

			crc = RspBodyBaseBean.getCrc(time, imei, App.key, info,
					App.user.getUid());
			//
			// crc = RspBodyBaseBean.getCrc(time, imei,
			// MD5.md5(App.user.getUserPass() + App.MD5_key),
			// info, App.user.getUid());

			auth = RspBodyBaseBean.getAuth(crc, time, imei,
					App.user.getUid());

			String[] values = { opt, auth, info };
			String result = HttpUtils.doPost(App.names, values,
					App.path);

			// remainShare
			Log.i("x", "加入合买的info====" + info);
			Log.i("x", "加入合买的auth====" + auth);
			Log.i("x", "加入合买的result====" + result);
			if ("-500".equals(result))
				return result;
			System.out.println("FollowInfoActivity---" + result);
			try {
				JSONObject object = new JSONObject(result);

				if ("0".equals(object.optString("error"))) {
					Log.i("x", "加入合买成功  ");
					App.user.setBalance(object.getLong("balance"));
					App.user.setFreeze(object.getDouble("freeze"));
					remainShare = object.getInt("remainShare");
					schedule = object.getInt("currentSchedule");
					return 0 + "";
				} else {
					return object.optString("error");
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				Log.e("s", e.getMessage());
			}
			return "-100";
		}

		@Override
		protected void onPostExecute(String result) {
			myHandler.sendEmptyMessage(Integer.parseInt(result));
			super.onPostExecute(result);
		}

	}

	/** 处理页面显示的 */
	class MyHandler extends Handler {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case App.ERROR_SUCCESS:
				Toast.makeText(FollowInfoActivity.this, "加入合买成功", Toast.LENGTH_SHORT).show();
				for (int i = 0; i < FollowFragment.listSchemes.size(); i++) {
					if (FollowFragment.listSchemes.get(i).getId()
							.equals(schemes.getId())) {
						FollowFragment.listSchemes.get(i).setSurplusShare(
								remainShare);
						FollowFragment.listSchemes.get(i).setSchedule(schedule);
						if (schedule == 100)
							FollowFragment.listSchemes.remove(i);
					}
				}
				FollowInfoActivity.this.finish();
				break;
			case -134:
				break;
			case -500:
				Toast.makeText(FollowInfoActivity.this,"连接超时" , Toast.LENGTH_SHORT).show();
				break;
			case -113:
				Toast.makeText(FollowInfoActivity.this, "方案已截止" , Toast.LENGTH_SHORT).show();
				break;
			case 2000:
				if (list_appGateWay.size() > 0) {
					tv_zong.setText("总计" + list_appGateWay.size() + "人跟单");
					ll_vip.setVisibility(View.VISIBLE);
					appGatewayAdapter = new AppGatewayAdapter(
							FollowInfoActivity.this, list_appGateWay);
					listView.setAdapter(appGatewayAdapter);
				}
				break;

			case -116:
				Toast.makeText(FollowInfoActivity.this,"方案剩余份数已不足一注，请手动刷新页面。" , Toast.LENGTH_SHORT).show();
				break;
			case -115:
				Toast.makeText(FollowInfoActivity.this, "余额不足",
						Toast.LENGTH_SHORT).show();
				Intent intent_alipay = new Intent();
				Bundle bundle_alipay = new Bundle();
				intent_alipay.setClass(FollowInfoActivity.this,
						AmountOfCharge.class);
				bundle_alipay.putInt("Type", 1);
				intent_alipay.putExtras(intent_alipay);
				// intent = new Intent();
				// intent.setClass(FollowInfoActivity.this,
				// PayWebActivity.class);
				FollowInfoActivity.this.startActivity(intent);
				break;
			default:
				break;
			}
			super.handleMessage(msg);
		}

	}

	/**
	 * 异步任务
	 */
	class MyAsynTaskBind extends AsyncTask<Void, Integer, String> {
		String error = "-1001";

		@Override
		protected String doInBackground(Void... params) {
			opt = "81";
			info = RspBodyBaseBean.changeJC_info(schemes.getId() + "");
			String key = App.key;
			if (App.user == null) {
				crc = RspBodyBaseBean.getCrc(time, imei, key, info, "-1");
				auth = RspBodyBaseBean.getAuth(crc, time, imei, "-1");
			} else {
				crc = RspBodyBaseBean.getCrc(time, imei, key, info,
						App.user.getUid());
				auth = RspBodyBaseBean.getAuth(crc, time, imei,
						App.user.getUid());
			}

			String[] values = { opt, auth, info };
			String result1 = HttpUtils.doPost(App.names, values,
					App.AppGateway);
			Log.i(TAG, "绑定信息的result----36-ada---" + result1);
			try {
				JSONArray jsonObjs = new JSONArray(result1);
				list_appGateWay = new ArrayList<AppGateway>();
				for (int i = 0; i < jsonObjs.length(); i++) {
					AppGateway appGateway = new AppGateway();
					JSONObject jsonObject = (JSONObject) jsonObjs.get(i);
					appGateway.setName(jsonObject.getString("Name").substring(
							0, 2)
							+ "***");
					appGateway.setDetailMoney(jsonObject
							.getString("DetailMoney"));
					appGateway.setShare(jsonObject.getString("Share"));
					appGateway.setDateTime(jsonObject.getString("Datetime"));
					list_appGateWay.add(appGateway);
				}
				Log.i(TAG, "绑定信息的result----36-ada---" + list_appGateWay.toString());
				Message message = new Message();
				message.what = 2000;
				myHandler.sendMessage(message);
			} catch (Exception e) {
				VolleyLog.e("JSONObject Exception:%s , response:%s",
						e.toString(), result1);
				Log.i(TAG, "绑定信息的result----36-ada---" +"error");
			}
			return error;
		}

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			dialog = BaseHelper.showProgress(context, null, "加载中....", true,
					true);
		}

		@Override
		protected void onPostExecute(String result) {
			if (dialog != null)
				dialog.dismiss();
			myHandler.sendEmptyMessage(Integer.parseInt(result));
			super.onPostExecute(result);
		}

	}

}
